home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 September / Enter 09 2006.iso / Internet / SpamExperts Home 1.1 / SpamExperts Home.exe / lib / spamexperts.modules / zope / interface / ro.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2006-07-14  |  1.4 KB  |  60 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. """Compute a resolution order for an object and it's bases
  5.  
  6. $Id: ro.py 25177 2004-06-02 13:17:31Z jim $
  7. """
  8.  
  9. def ro(object):
  10.     '''Compute a "resolution order" for an object
  11.     '''
  12.     return mergeOrderings([
  13.         _flatten(object, [])])
  14.  
  15.  
  16. def mergeOrderings(orderings, seen = None):
  17.     """Merge multiple orderings so that within-ordering order is preserved
  18.  
  19.     Orderings are constrained in such a way that if an object appears
  20.     in two or more orderings, then the suffix that begins with the
  21.     object must be in both orderings.
  22.  
  23.     For example:
  24.  
  25.     >>> _mergeOrderings([
  26.     ... ['x', 'y', 'z'],
  27.     ... ['q', 'z'],
  28.     ... [1, 3, 5],
  29.     ... ['z']
  30.     ... ])
  31.     ['x', 'y', 'q', 1, 3, 5, 'z']
  32.  
  33.     """
  34.     if seen is None:
  35.         seen = { }
  36.     
  37.     result = []
  38.     orderings.reverse()
  39.     for ordering in orderings:
  40.         ordering = list(ordering)
  41.         ordering.reverse()
  42.         for o in ordering:
  43.             if o not in seen:
  44.                 seen[o] = 1
  45.                 result.append(o)
  46.                 continue
  47.         
  48.     
  49.     result.reverse()
  50.     return result
  51.  
  52.  
  53. def _flatten(ob, result):
  54.     result.append(ob)
  55.     for base in ob.__bases__:
  56.         _flatten(base, result)
  57.     
  58.     return result
  59.  
  60.